Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
marked-gfm-heading-id
Advanced tools
Add ids to headings like GitHub.
import { marked } from "marked";
import { gfmHeadingId } from "marked-gfm-heading-id";
// or UMD script
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
// <script src="https://cdn.jsdelivr.net/npm/marked-gfm-heading-id/lib/index.umd.js"></script>
const options = {
prefix: "my-prefix-",
};
marked.use(gfmHeadingId(options));
marked("# heading");
// <h1 id="my-prefix-heading">heading</h1>
getHeadingList
is a function that is exported to provide the list of headings.
The headings will each be an object with the following properties:
text
: The rendered HTML for the headinglevel
: The heading level (1-7)id
: The id given to the heading including any prefiximport { marked } from "marked";
import { gfmHeadingId, getHeadingList } from "marked-gfm-heading-id";
marked.use(gfmHeadingId({prefix: "my-prefix-"}), {
hooks: {
postprocess(html) {
const headings = getHeadingList();
return `
<ul id="table-of-contents">
${headings.map(({id, text, level}) => `<li><a href="#${id}" class="h${level}">${text}</a></li>`)}
</ul>
${html}`;
}
}
});
marked("# heading");
// <ul id="table-of-contents">
// <li><a href="#my-prefix-heading" class="h1">heading</a></li>
// </ul>
// <h1 id="my-prefix-heading">heading</h1>
resetHeadings
is a function to purge the stored list of headings and reset the Slugger. This is only needed when the globalSlugs option ( see below) is set to true and you wish to reset the slugger and exportable Headers list.
options
option | type | default | description |
---|---|---|---|
prefix | string | "" | A string to prepend to all ids. |
globalSlugs | bool | false | Track ids from one use of marked to the next. This ensures unique headers when parsing multiple markdown fragments and rendering the results as a single document. When set to false, the slugger and headers lists are cleared on every marked run. |
FAQs
marked GFM heading ids
The npm package marked-gfm-heading-id receives a total of 44,522 weekly downloads. As such, marked-gfm-heading-id popularity was classified as popular.
We found that marked-gfm-heading-id demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.